/*
 * Album.java
 *
 * Created on 21 novembre 2007, 21:35
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package Modele;

/**
 *
 * @author Soufiane GARCH
 *
 * If you want to change anything in this source, please contact me
 */

import java.util.ArrayList;
import java.io.File;
import java.util.Observable;


public class Album extends Observable implements EnsembleImage{
    private String nom;
    private String legende;
    private ArrayList images;
    
    /** Creates a new instance of Album 
     *
     *@param String nom
     *
     */
    public Album(String nom) {
        this.nom = nom;
        this.legende = "";
        this.images = new ArrayList();
    }
    
    /** Creates a new instance of Album 
     *
     *@param String nom
     *@param String legende
     */
    public Album(String nom, String legende) {
        this.nom = nom;
        this.legende = legende;
        this.images = new ArrayList();
    }

    /** Creates a new instance of Album 
     *
     *@param String nom
     *@param ArrayList images
     */
    public Album(String nom, ArrayList images) {
        this.nom = nom;
        this.images = images;
    }
    
    /** Creates a new instance of Album 
     *
     *@param String nom
     *@param String legende
     *@param ArrayList images
     */
    public Album(String nom, String legende, ArrayList images) {
        this.nom = nom;
        this.legende = legende;
        this.images = images;
    }
    
    /**
     *Set the name of the album
     *
     *@param String nom
     *
     *@return void
     */
    public void setNom(String nom){
        this.nom = nom;
    }
    
     /**
     *Set the legende of the album
     *
     *@param String legende
     *
     *@return void
     */
    public void setLegende(String legende){
        this.legende = legende;
    } 
    
     /**
     *Set the list of the images of the album
     *
     *@param ArrayList images
     *
     *@return void
     */
    public void setListImages(ArrayList images){
        this.images = images;
    }
      
     /**
     *Get the name of the album
     *
     *@param void
     *
     *@return String
     */
    public String getNom(){
        return this.nom;
    }
    
     /**
     *Get the legende of the album
     *
     *@param void
     *
     *@return String
     */
    public String getLegende(){
        return this.legende;
    } 
    
     /**
     *Set the list of the images of the album
     *
     *@param void
     *
     *@return ArrayList
     */
    public ArrayList getListImages(){
        return this.images;
    }
    /*
    public void trierImage(int critere){
        switch(critere){
            case 1:
                Collections.sort(images, new 
                    Comparator()
                    {
                        public int compare(Object a, Object b){
                            String img1 = ((ModeleImage) a).getNom();
                            String img2 = ((ModeleImage) b).getNom();
                            
                            if (img1.compareTo(img2) > 0) return -1;
                            else if (img1.compareTo(img2) == 0) return 0;
                            else return 1;
                        }    
                    });
                break;
                
            case 2:
                Collections.sort(images, new 
                    Comparator()
                    {
                        public int compare(Object a, Object b){
                            String img1 = ((ModeleImage) a).getExtention();
                            String img2 = ((ModeleImage) b).getExtention();
                            
                            if (img1.compareTo(img2) > 0) return -1;
                            else if (img1.compareTo(img2) == 0) return 0;
                            else return 1;
                        }    
                    });
                break;
                
            case 3:
                Collections.sort(images, new 
                    Comparator()
                    {
                        public int compare(Object a, Object b){
                            long img1 = ((ModeleImage) a).getTaille();
                            long img2 = ((ModeleImage) b).getTaille();
                            
                            if (img1 > img2) return 1;
                            else if (img1 == img2) return 0;
                            else return -1;
                        }    
                    });                
                break;
                
            default:
                Collections.sort(images, new 
                    Comparator()
                    {
                        public int compare(Object a, Object b){
                            String img1 = ((ModeleImage) a).getNom();
                            String img2 = ((ModeleImage) b).getNom();
                            
                            if (img1.compareTo(img2) > 0) return -1;
                            else if (img1.compareTo(img2) == 0) return 0;
                            else return 1;
                        }    
                    });
                break;
            
        }
    }*/
    
    public void ajouterImage(ModeleImage img){
        images.add(img);
    }
    
    public void modifierNom(String nom){
        setNom(nom);
    }
 
    /**
     * Surdefinition de la fonction supprimerImage de l'interface EnsembleImage
     * 
     * 
     * @paramModeleImagee image
     * @return void
     */
    public void supprimerImage(ModeleImage img){
        supprimerImage(img, false);
    }
    
    public void supprimerImage(ModeleImage img, boolean physique){
        if (physique == false)
            images.remove(img);
        else{
            File file = img.getFile();
            file.delete();
            images.remove(img);
        }
    }

    @Override
    public String toString()
    {
	return this.nom;
    }
    
    public ArrayList getListofImage(){
        return this.images;
    }
    
    public boolean equals(String s2){
        String s1 = this.getNom();
        if (s2.length() != s1.length())
            return false;
        
        for(int i = 0; i<s2.length(); i++){
            if (s1.charAt(i) != s2.charAt(i))
            return false;
        }
        
        return true;
    }
}
